package cn.sinjet.myview;

import com.mgroup.wazehelper.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import cn.sinjet.viewmodel.OnMyDlgActionListener;

public class HintAlertDlg implements OnClickListener,OnDismissListener{
	Context context;
	AlertDialog dlg;
	TextView vMessage;
	Button btnPositive,btnNegative;
	String positiveText = "确定";
	String negativeText = "取消";
	OnMyDlgActionListener actionListener = null;
	public HintAlertDlg(Context context){
		this.context = context;
	}
	
	public void setButtonText(String positive,String negative){
		this.positiveText = positive;
		this.negativeText = negative;
	}
	
	public void show(String message,OnMyDlgActionListener actionListener){
		dlg = new AlertDialog.Builder(context).create();
		dlg.show();
		dlg.setOnDismissListener(this);
		Window window = dlg.getWindow();
		window.setContentView(R.layout.layout_hint_alert_dlg);
		vMessage = (TextView)window.findViewById(R.id.dlg_message);
		vMessage.setText(message);
		btnPositive = (Button)window.findViewById(R.id.dlg_positive);
	    btnNegative = (Button)window.findViewById(R.id.dlg_negative);
	    btnPositive.setText(positiveText);
	    btnNegative.setText(negativeText);
	    btnPositive.setOnClickListener(this);
	    btnNegative.setOnClickListener(this);
	    this.actionListener = actionListener;
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch(view.getId()){
		case R.id.dlg_negative:
		   dlg.dismiss();
		   if(actionListener != null) actionListener.onNegative();
		break;
		case R.id.dlg_positive:
	       dlg.dismiss();
		   if(actionListener != null) actionListener.onPositive();
		break;
		}
	}

	@Override
	public void onDismiss(DialogInterface arg0) {
		// TODO Auto-generated method stub
		if(actionListener != null)
			actionListener.onDismiss();
	}
	
}
